/********************************************************/
/*	vec2 class DLLEXPORT by George Chew							*/
/*	For use in GeorgeLib								*/
/*	Created Mar 2013									*/
/*														*/
/*	Version 0000										*/
/********************************************************/

#ifndef __VEC2_H__
#define __VEC2_H__

#include "stdafx.h"

#define _USE_MATH_DEFINES
#include <math.h>

#define RADTODEG 180.0f/(float)M_PI
#define DEGTORAD (float)M_PI/180.0f
#define ZEROTOLERANCE 0.00001
#define ZEROTOLERANCEDIGITS 5

	/*		How to use this class DLLEXPORT DLLEXPORT		*/
	// vec2 myVec(42,69);
	// float myArr[2]; myVec.asArray(myArr);
	// std::cout << myVec << std::endl;

class vec2
{
public:
	float x, y;

public:
	/* Constructors and Destructor */
	vec2	(void);							// constructor : an empty vector, (0,0)
	vec2	(float X, float Y);				// constructor : from three values, (x,y)
	vec2	(float a);						// constructor : from one value, (a,a)
	vec2	(float * v);					// constructor : from an array of float[2]
	vec2	(const vec2 &v);				// constructor : from another vector
	~vec2	(void);							// destructor

	/* Class Accessors */
	float	total			(void);			// addition of all the values of the vector
	vec2	negated			(void);			// negative of this vector
	void	asArray			(float *arr);	// values of this vector to an array

	/* Vector Calculations */
	float	magnitude		(void);			// magnitude of this vector
	vec2	normal			(void);			// unit vector of this vector
	vec2	direction		(void);			// angles between (1,1) and this vector on each axis in degrees
	float	distancebetween	(vec2 v);		// distance between this vector and v
	float	anglebetween	(vec2 v);		// angle between this vector and v
	float	dotproduct		(vec2 v);		// dot product between this vector and v

	/* Operator Overloads */
	vec2	operator+		(vec2 v);		// add vector v to this vector
	void	operator+=		(vec2 v);		// add vector v to this vector
	vec2	operator-		(vec2 v);		// subtract vector v from this vector
	void	operator-=		(vec2 v);		// subtract vector v from this vector
	vec2	operator*		(float f);		// multiply this vector by f
	void	operator*=		(float f);		// multiply this vector by f
	vec2	operator/		(float f);		// divide this vector by f
	void	operator/=		(float f);		// divide this vector by f
	float	operator*		(vec2 v);		// dot product between this vector and vector v

	/* Comparison Operator Overloads */
	bool	operator==		(vec2 v);		// checks if vector is equal to another vector
	bool	operator!=		(vec2 v);		// checks if vector is not equal to another vector
	bool	operator>		(vec2 v);		// checks if vector magnitude is more than another vector's magnitude
	bool	operator>=		(vec2 v);		// checks if vector magnitude is more than or equal to another vector's magnitude
	bool	operator<		(vec2 v);		// checks if vector magnitude is less than another vector's magnitude
	bool	operator<=		(vec2 v);		// checks if vector magnitude is less than or equal to another vector's magnitude

	// values input using operator()
	void	operator()		(float X, float Y);

	// negative value of vector
	friend	vec2			operator-		(vec2 v);

	// get values using [] operator
	float	operator[]		(int a);

	// output vector contents to console
	friend	ostream&		operator<<		(ostream &os, vec2 &v);

	// round up numbers to 5 digits after the decimal point
	friend	vec2			detectzero		(vec2 vector);
};

typedef const vec2 cvec2;

#endif // __VEC2_H__